<template>
  <div class="app-container" :v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" label-position="top">
      <el-form-item label="群组信息">
        <el-link type="success" disabled>{{form.title}}</el-link>
        <el-link type="primary" disabled>{{form.chatId}}</el-link>
      </el-form-item>
      <el-form-item label="入群验证" prop="status">
        <el-select v-model="form.status" placeholder="验证开关">
          <el-option
            v-for="dict in dict.type.bot_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="消息文本" prop="content">
        <el-input v-model="form.content" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="验证方式" prop="type">
        <el-select v-model="form.type" placeholder="请选择验证方式">
          <el-option
            v-for="dict in dict.type.bot_chat_verify_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="超时时间(秒)" prop="timeOut">
        <el-select v-model="form.timeOut" placeholder="请选择超时时间(秒)">
          <el-option
            v-for="dict in dict.type.bot_common_time"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="删除验证消息(秒)" prop="delMsgTime">
        <el-select v-model="form.delMsgTime" placeholder="请选择删除验证消息(秒)">
          <el-option
            v-for="dict in dict.type.bot_common_time"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="封禁时长" prop="banTime">
        <el-select v-model="form.banTime" placeholder="请选择封禁时长">
          <el-option
            v-for="dict in dict.type.bot_ban_time"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="Premium自动通过" prop="autoPremium">-->
<!--        <el-select v-model="form.autoPremium" placeholder="请选择Premium自动通过">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.bot_chat_verify_premium"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          ></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" v-hasPermi="['bot:verify:edit']" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import {getVerify, updateVerify} from "@/api/bot/verify";

export default {
  name: "VerifyDetail",
  dicts: ['bot_chat_verify_type', 'bot_ban_time', 'bot_chat_verify_premium', 'bot_common_time','bot_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入群验证表格数据
      verifyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      // 表单参数
      form: {},
      query:{},
      // 表单校验
      rules: {
        chatId: [
          { required: true, message: "群组ID不能为空", trigger: "blur" }
        ],
        content: [
          { required: true, message: "消息文本不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "验证方式不能为空", trigger: "change" }
        ],
        timeOut: [
          { required: true, message: "超时时间(秒)不能为空", trigger: "change" }
        ],
        delMsgTime: [
          { required: true, message: "删除验证消息(秒)不能为空", trigger: "change" }
        ],
        banTime: [
          { required: true, message: "封禁时长不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.query = this.$route.query
    this.form.chatId = this.query.chatId
    this.form.title = this.query.title
    this.queryData()
  },
  methods: {
    //返回上个页面
    back(){
      this.$tab.closeOpenPage({ path: "/tg/group_client" });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chatId: this.query.chatId,
        title:this.query.title,
        content: null,
        type: '1',
        timeOut: 120,
        delMsgTime: 120,
        banTime: 0,
        autoPremium: '0',
        remark: null,
        orderNum: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createById: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },

    /** 修改按钮操作 */
    queryData() {
      this.reset();
      getVerify(this.query.chatId).then(response => {
        this.loading = false
        if(response.data){
          this.form = response.data;
          this.form.title = this.query.title
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        updateVerify(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.back()
        });
      });
    },
  }
};
</script>
<style>
.app-container .tip {
  padding: 8px 16px;
  background-color: #ecf8ff;
  border-radius: 4px;
  border-left: 5px solid #50bfff;
  margin: 20px 0;
  height: 100px;
}
</style>
